{#
This file is part of EC-CUBE

Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.

http://www.ec-cube.co.jp/

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#}
{% extends 'default_frame.twig' %}

{% set menus = ['setting', 'shop', 'shop_tax'] %}

{% block title %}基本情報設定{% endblock %}
{% block sub_title %}税率設定{% endblock %}

{% form_theme form 'Form/bootstrap_3_horizontal_layout.html.twig' %}

{% block stylesheet %}
<link rel="stylesheet" href="{{ app.config.admin_urlpath }}/assets/css/bootstrap-datetimepicker.min.css">
{% endblock stylesheet %}

{% block javascript %}
<script src="{{ app.config.admin_urlpath }}/assets/js/vendor/moment.min.js"></script>
<script src="{{ app.config.admin_urlpath }}/assets/js/vendor/moment-ja.js"></script>
<script src="{{ app.config.admin_urlpath }}/assets/js/vendor/bootstrap-datetimepicker.min.js"></script>
<script>
$(function() {

    $('#tax_rule_apply_date').datetimepicker({
        locale: 'ja',
        format: 'YYYY-MM-DD HH:mm',
        useCurrent: false,
        showTodayButton: true
    });

});

    function fnChange(action) {
        document.form1.action = action;
        document.form1.submit();
        return false;
    }
</script>
{% endblock javascript%}

{% block main %}
    <form name="form1" role="form" class="form-horizontal" id="form1" method="post" action="
    {%- if TargetTaxRule.id is null -%}
        {{ url('admin_setting_shop_tax_new')}}
    {%- else -%}
        {{ url('admin_setting_shop_tax_edit', { id : TargetTaxRule.id }) }}
    {%- endif -%}">
        {{ form_widget(form._token) }}
    <div id="tax_rule_wrap" class="row">
        <div id="tax_rule_box" class="col-md-12">
            {# 個別税率設定 #}
            <div id="tax_rule_box__body" class="box">
                <div id="tax_rule_box__header" class="box-header">
                    <h3 class="box-title">個別税率設定</h3>
                </div><!-- /.box-header -->
                <div id="tax_rule_box__body_inner" class="box-body">
                    {{ form_row(form.option_product_tax_rule) }}
                </div><!-- /.box-body -->
            </div><!-- /.box -->
            <div id="tax_rule_box__insert_button" class="row btn_area2">
                <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-3 text-center">
                    <button class="btn btn-primary btn-block btn-lg"
                            onclick="fnChange('{{ url('admin_setting_shop_tax_edit_param') }}'); return false;">登録</button>

                </div>
            </div>

            {# 共通税率設定 #}
            <div id="tax_common_rule_box" class="box">
                <div id="tax_common_rule_box__header" class="box-header">
                    <h3 class="box-title">共通税率設定</h3>
                </div><!-- /.box-header -->
                <div id="tax_common_rule_box__body" class="box-body">
                    {{ form_row(form.tax_rate) }}
                    {{ form_row(form.calc_rule) }}
                    {% if TargetTaxRule.default_tax_rule == false %}
                        {{ form_row(form.apply_date) }}
                    {% endif %}
                    <div class="extra-form">
                        {% for f in form.getIterator %}
                            {% if f.vars.name matches '[^plg*]' %}
                                {{ form_row(f) }}
                            {% endif %}
                        {% endfor %}
                    </div>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
            <div id="tax_common_rule_box__insert_button" class="row btn_area2">
                <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-3 text-center">
                    <button class="btn btn-primary btn-block btn-lg" type="submit">登録</button>
                </div>
            </div>

            {# 税率一覧 #}
            <div id="tax_rule_list" class="box">
                <div id="tax_rule_list__header" class="box-header">
                    <h3 class="box-title">税率一覧</h3>
                </div><!-- /.box-header -->
                <div id="tax_rule_list__body" class="box-body">
                    <div id="tax_rule_list__list" class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr id="tax_rule_list__header">
                                <th id="tax_rule_list__header_id">ID</th>
                                <th id="tax_rule_list__header_tax_rate">消費税率</th>
                                <th id="tax_rule_list__header_calc_rule">課税規則</th>
                                <th id="tax_rule_list__header_default_tax_rule">適用日時</th>
                                <th id="tax_rule_list__header_menu_box">&nbsp;</th>
                            </tr>
                            </thead>
                            <tbody>
                            {%  for TaxRule in TaxRules %}
                            <tr id="tax_rule_list__item--{{ TaxRule.id }}">
                                <td id="tax_rule_list__id--{{ TaxRule.id }}">{{ TaxRule.id }}</td>
                                <td id="tax_rule_list__tax_rate--{{ TaxRule.id }}">{{ TaxRule.tax_rate }}%</td>
                                <td id="tax_rule_list__calc_rule--{{ TaxRule.id }}">{{ TaxRule.calc_rule }}</td>
                                <td id="tax_rule_list__default_tax_rule--{{ TaxRule.id }}">{{ TaxRule.default_tax_rule  ? '基本税率設定' : TaxRule.apply_date|date('Y/m/d  H:i') }}</td>
                                <td id="tax_rule_list__menu_box--{{ TaxRule.id }}" class="icon_edit">
                                    <div id="tax_rule_list__menu_box_toggle" class="dropdown">
                                        <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><svg class="cb cb-ellipsis-h"> <use xlink:href="#cb-ellipsis-h" /></svg></a>
                                        <ul id="tax_rule_list__menu--{{ TaxRule.id }}" class="dropdown-menu dropdown-menu-right">
                                            <li><a href="{{ url('admin_setting_shop_tax_edit', { id : TaxRule.id }) }}">編集</a></li>
                                            {% if TaxRule.default_tax_rule %}
                                                <li><a>削除</a></li>
                                            {% else %}
                                                <li><a href="{{ url('admin_setting_shop_tax_delete', { id : TaxRule.id }) }}" {{ csrf_token_for_anchor() }} data-method="delete">削除</a></li>
                                            {% endif %}
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>
    </div>
    </form>
{% endblock %}